# 运行入口文件
import os
import time

import pytest

from Config.Config import Config
from Utils.SetDefault import create_settings_js_file, insert_script_tag

if __name__ == '__main__':

    # pytest.main(["-v", "-s", f'--alluredir={AllureResult}', "--clean-alluredir"])
    # pytest.main(["-v", "-s", '--reruns=3', f'--alluredir={AllureResult}', "--clean-alluredir"])
    # os.system(f'allure generate {AllureResult} -o {AllureReport} --clean')

    # pytest.main()

    try:
        AllureReport = Config.test_report_dir
        AllureResult = Config.test_result_dir
        Screenshot = Config.test_screenshot_dir
        os.system(f"rm {os.path.join(Screenshot, '*.png')}")

        time_start = time.time()
        pytest.main()
        time_end = time.time()
        timeall = (time_end - time_start)
        print("分布式执行用例总时间(: .2f)s".format(timeall))

        os.system(f'allure generate {AllureResult} -o {AllureReport} --clean')

        # # 生成设置成默认为中文的js文件
        create_settings_js_file(AllureReport)
        # # 在修改index.html代码，引入设置文件
        insert_script_tag(AllureReport, f'<script src="settings.js"></script>')
        # # os.system("allure serve ./reports/tmp")
        os.system(f'allure open -h 127.0.0.1 -p 8084 {AllureReport}')

    except Exception as e:
        print("发生错误:", e)
